<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
    <head>
        <title>Title</title>
        <script src="${pageContext.request.contextPath}/js/jquery-3.3.1.min.js"></script>
        <script>

            $(function(){

                $("#all").click(function(){
                    $("input[type='checkbox']").prop("checked",$(this).prop('checked'));
                });

                $("#remove").click(function () {
                    $("#f").submit();
                });

                $("a[name='modify']").click(function(){
                    var productId=$("input[type='checkbox']",$(this).parent().parent()).val();
                    var num=$("input[type='text']",$(this).parent().parent()).val();

                    $(this).prop("href","${pageContext.request.contextPath}/modify.cart?productId="+productId+"&num="+num);
                });

            });

        </script>
    </head>
    <body>
        <h1>我的购物车</h1>
        <hr/>

        <form id="f" action="${pageContext.request.contextPath}/removeByProductIds.cart" method="post">
            <table border="1">
                <tr>
                    <th>
                        <input type="checkbox" id="all"/>全选
                    </th>
                    <th>序号</th>
                    <th>商品</th>
                    <th>数量</th>
                    <th>价格</th>
                    <th>操作</th>
                </tr>


                <c:forEach items="${cart.items}" var="item" varStatus="s">
                    <tr>
                        <td>
                            <input type="checkbox" name="productIds" value="${item.product.id}"/>
                        </td>
                        <td>${s.count}</td>
                        <td>${item.product.name}</td>
                        <td>
                            <input type="text" size="3" style="border: 0px;" value="${item.num}"/>
                        </td>
                        <td>${item.price}</td>
                        <td>
                            <a href="${pageContext.request.contextPath}/removeByProductId.cart?productId=${item.product.id}" onclick="return confirm('是否确认删除？');">删除</a>
                            <a href="javascript:" name="modify">修改</a>
                        </td>
                    </tr>
                </c:forEach>


            </table>
        </form>


        总计：${cart.price}元<br/>
        <a href="javascript:" id="remove">删除选中项</a>
        <a href="${pageContext.request.contextPath}/clear.cart">清空购物车</a>
        <a href="${pageContext.request.contextPath}/list.product">继续购物</a>
        <a href="${pageContext.request.contextPath}/shop/order.jsp">结算</a>
    </body>
</html>
